from typing import Dict, List, Optional, Tuple, Union

# from ..core.datatypes import Language
from enum import Enum
from instruction_re.formatters.format_utils import *

from .MainTaskFormatter import MainTaskFormatter
from .EntityFormatter import EntityFormatter


class Language(Enum):
    EN = "en"


class ExampleFormatter(MainTaskFormatter):
    def __init__(self, **kwargs) -> None:
        super().__init__(**kwargs)

    def from_examples(
        self, examples: Optional[List[Dict[str, Union[str, List[str]]]]]
    ) -> str:
        if examples is None:
            return None

        answers = []

        for example in examples:
            sentence = add_sentence_prefix(example["sentence"])

            entity_prefix = add_conditions_prefix(
                EntityFormatter.from_relations(relations=example["relations"])
            )

            output = add_answer_prefix(
                self.format_answer(relations=example["relations"])
            )

            answers.append(sentence + " " + entity_prefix + " " + output)

        return " ".join(answers)
